#pragma once
#include "TrTypes.h"


class CThostFtdcTraderApi;
class CTrMarketSpi;
class CTrTraderSpi;

class CTrService
{
public:
    virtual void OnResponse(Tr_ResponseID rId, void* wParam, void* lParam) = 0;
};

class CTrImpl : public CTrService
{
public:
    CTrImpl();
    virtual ~CTrImpl();
    virtual void OnResponse(Tr_ResponseID rId, void* wParam, void* lParam) override;
    // =============================================
    void ImplAddReceiver(CTrReceiver* receiver);
    void ImplDelReceiver(CTrReceiver* receiver);
    void ImplCreatePath(const char* Path);
    void ImplUserLogin(const char* BrokerID, const char* UserID, const char* Password, const char* Front, const char* AppID, const char* AuthCode);
    void ImplUserLogout();
    void ImplAddSubscribe(const char* Contract);
    void ImplRspPosition();
    void ImplRspTradingAccount();
    void ImplRspInstrument();
    void ImplQuote(const char* Instrument, int iStyle);
    void ImplBuy(TrRtnOrderField order);
    void ImplSell(TrRtnOrderField order);
    void ImplShort(TrRtnOrderField order);
    void ImplCover(TrRtnOrderField order);
    void ImplRevoke(CThostFtdcOrderField order);
    bool ImplbReady();
    void ImplRelease();
    bool ImplMarketStatus();
    bool ImplTradeStatus();
    // =============================================
    void    ImplStart();
    void    ImplStop();
    void    ImplSetFront(const char* Front);
    std::vector<std::string>        m_ImplSubscribes;
    std::map<const char*, CThostFtdcInstrumentField>  m_ImplInstruments;
protected:
    CThostFtdcTraderApi* m_ImplTrTraderApi = nullptr;
    CTrTraderSpi* m_ImplTrTraderSpi = nullptr;
    std::vector<CTrReceiver*>           m_ImplReceivers;
    Tr_InstrumentStatus                 m_InstrumentStatus;
    CTrMarketSpi* m_ImplMarketSpi;
    const char* m_ImplFronts;
    bool                                m_bMarketStatus = false;
    bool                                m_bTradeStatus = false;
};